#include <iostream>
using namespace std;

struct ListNode{
  int val;
  ListNode* next;
  ListNode()
    :val(0),
    next(NULL)
  {}
  ListNode(int x)
    :val(x),
    next(NULL)
  {}

};

int main()
{
  ListNode* l1 = new ListNode();
  ListNode* l2 = new ListNode(1);
  ListNode* l3 = new ListNode(2);
  ListNode* l4 = new ListNode(3);
  ListNode* l5 = new ListNode(4);

  l1->next = l2;
  l2->next =l3;
  l3->next = l4;
  l4->next = l5;


  ListNode* p = l1;
  while(p){
    cout << p->val << " ";
    p = p->next;
  }
  cout << endl;

  return 0;
}
